/*
Copyright (C) 2015 Marien Raat, Jochem Raat

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <button.h>

Button::Button(sf::Vector2f position, sf::Font *font,
               std::string text, sf::Texture *texture,
               sf::Texture *clickedTexture, sf::Vector2f size)
               : rect(position, size)
{
    this->texture = texture;
    this->clickedTexture = clickedTexture;

    buttonText.setString(text);
    buttonText.setFont(*font);
    buttonText.setPosition(position + sf::Vector2f(padding, padding));
    buttonText.setColor(sf::Color::Black);
    buttonText.setCharacterSize(15);
    
    button.setPosition(position);
    button.setTexture(*texture);
}

void Button::draw(sf::RenderWindow *window)
{
    window->draw(button);
    window->draw(buttonText);

    if (!sf::Mouse::isButtonPressed(sf::Mouse::Left))
        button.setTexture(*texture);
}

bool Button::click(sf::RenderWindow *window)
{
    button.setTexture(*clickedTexture);
    draw(window);
    window->display();
}

void Button::setNormalTexture(sf::Texture *texture)
{
    this->texture = texture;
}

void Button::setClickedTexture(sf::Texture *texture)
{
    this->clickedTexture = texture;
}
